package com.jcodecraeer.xrecyclerview.progressindicator.indicator;

import ohos.agp.animation.Animator;
import ohos.agp.animation.AnimatorValue;
import ohos.agp.render.Canvas;
import ohos.agp.render.Paint;


import java.util.ArrayList;
import java.util.List;

public class BallScaleIndicator extends BaseIndicatorController {

    float scale=1;
    int alpha=255;

    @Override
    public void draw(Canvas canvas, Paint paint) {
        float circleSpacing=4;

        canvas.scale(scale,scale,getWidth()/2,getHeight()/2);
        paint.setAlpha(120);
        canvas.drawCircle(getWidth()/2,getHeight()/2,getWidth()/3-circleSpacing,paint);
    }

    @Override
    public List<Animator> createAnimation() {
        List<Animator> animators=new ArrayList<>();
        AnimatorValue scaleAnim = new AnimatorValue();
        scaleAnim.setDuration(1200);
        scaleAnim.setLoopedCount(-1);
        scaleAnim.setCurveType(Animator.CurveType.SMOOTH_STEP);
        scaleAnim.setValueUpdateListener(new AnimatorValue.ValueUpdateListener() {
            @Override
            public void onUpdate(AnimatorValue animatorValue, float v) {
                scale = v;
                postInvalidate();
            }
        });

        scaleAnim.start();
        animators.add(scaleAnim);
        return animators;
    }


}

